package atm;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 菜单界面
 */
public class MenuPanel extends JPanel implements ActionListener {
    private ATMFrame atmFrame;
    private ImageIcon depositImg = new ImageIcon("images/buttonSave.jpg");
    private ImageIcon withdrawTmg = new ImageIcon("images/buttonGet.jpg");
    private ImageIcon queryImg = new ImageIcon("images/buttonFind.jpg");
    private ImageIcon signImg = new ImageIcon("images/buttonOff.jpg");
    private ImageIcon changeImg = new ImageIcon("images/buttonModify.jpg");
    private ImageIcon transferImg = new ImageIcon("images/buttonTransferPanel.jpg");
    private ImageIcon switchImg = new ImageIcon("images/buttonSwitch.jpg");
    //存款
    private JButton depositBtn = new JButton(depositImg);
    //取款
    private JButton withdrawbtn = new JButton(withdrawTmg);
    //查询
    private JButton queryBtn = new JButton(queryImg);
    //退出
    private JButton signBtn = new JButton(signImg);
    //改密
    private JButton changeBtn = new JButton(changeImg);
    //转账
    private JButton transferBtn = new JButton(transferImg);//转账
    private JButton switchBtn = new JButton(switchImg);//切换账号
    public MenuPanel(ATMFrame atmFrame){
        this.atmFrame = atmFrame;
        this.setLayout(null);
        depositBtn.setBounds(0,150,140,50);
        withdrawbtn.setBounds(0,300,140,50);
        queryBtn.setBounds(0,450,140,50);
        signBtn.setBounds(0,600,140,50);
        changeBtn.setBounds(884,150,140,50);
        transferBtn.setBounds(884,300,140,50);
        switchBtn.setBounds(884,450,140,50);
        depositBtn.addActionListener(this);
        withdrawbtn.addActionListener(this);
        queryBtn.addActionListener(this);
        signBtn.addActionListener(this);
        changeBtn.addActionListener(this);
        transferBtn.addActionListener(this);
        switchBtn.addActionListener(this);
        this.add(depositBtn);
        this.add(withdrawbtn);
        this.add(queryBtn);
        this.add(signBtn);
        this.add(changeBtn);
        this.add(transferBtn);
        this.add(switchBtn);
        this.setOpaque(false);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == depositBtn){
            atmFrame.switchPanel("save");
        }else if (e.getSource() == withdrawbtn){
            atmFrame.switchPanel("get");
        }else if (e.getSource() == queryBtn){
            atmFrame.getSearchPanel().showBlance(atmFrame.getLoginUser().getBlance());
            atmFrame.switchPanel("search");

        }else if (e.getSource() == signBtn){
            JOptionPane.showMessageDialog(null, "感谢使用！");
            System.exit(0);
        }else if (e.getSource() == changeBtn){
            atmFrame.switchPanel("changePwd");
        }else if (e.getSource() == transferBtn){
            atmFrame.switchPanel("trans");
        }else if (e.getSource() == switchBtn){
            atmFrame.switchPanel("login");
        }
    }
}
